﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using TomShane.Neoforce.Controls;

namespace tactics.GUI.DialogBox
{
    public delegate void okFunction();
    public delegate void cancelFunction();

    public class DialogBox
    {
        Manager guiManager;
        Dialog dialog;
        okFunction okCallback;
        cancelFunction cancelCallback;

        public DialogBox(string title, string caption, string body, int WidthIn, int heightIn, bool showCancel, okFunction okDelegate, cancelFunction cancelDelegate)
        {
            guiManager = TacticsEngine.Instance.GuiManager;
            okCallback = okDelegate;
            cancelCallback = cancelDelegate;

            dialog = new Dialog(guiManager);
            dialog.Text = title;
            dialog.Caption.Text = caption;
            dialog.Description.Text = body;
            dialog.Init();
            dialog.CloseButtonVisible = false;
            dialog.Height = heightIn;
            dialog.Width = WidthIn;
            dialog.Center();
            dialog.Visible = true;

            Button okButton = new Button(guiManager);
            okButton.Init();
            okButton.Text = "OK";
            okButton.Width = 72;
            okButton.Height = 24;
            okButton.Left = (dialog.ClientWidth / 2) - 4 - okButton.Width;
            okButton.Top = dialog.ClientHeight - okButton.Height - 5;
            okButton.Anchor = Anchors.Bottom;
            okButton.Parent = dialog;
            okButton.Click += new TomShane.Neoforce.Controls.EventHandler(CloseDialogOk);
            //okButton.Focused = true;

            if (showCancel)
            {
                Button cancelButton = new Button(guiManager);
                cancelButton.Init();
                cancelButton.Text = "Cancel";
                cancelButton.Width = 72;
                cancelButton.Height = 24;
                cancelButton.Left = (dialog.ClientWidth / 2) + 90 - cancelButton.Width;
                cancelButton.Top = dialog.ClientHeight - cancelButton.Height - 5;
                cancelButton.Anchor = Anchors.Bottom;
                cancelButton.Parent = dialog;
                cancelButton.Click += new TomShane.Neoforce.Controls.EventHandler(CloseDialogCancel);
            }

            guiManager.Add(dialog);
        }

        private void CloseDialogOk(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            if (okCallback != null)
            {
                okCallback();
            }
            dialog.Close();
        }

        private void CloseDialogCancel(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            if (cancelCallback != null)
            {
                cancelCallback();
            }
            dialog.Close();
        }
    }
}
